package com.bw.controller;


import com.bw.domain.ParkManager;
import com.bw.service.ParkManagerService;
import com.bw.utils.R;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * @author bobo棒
 * @date 2025年02月27日 14:32
 */

@Controller
@RequestMapping("park")
public class ParkController {
    @Autowired
    ParkManagerService parkManagerService;

    /**
     * 添加或修改停车场
     * @param parkManager
     * @return
     */
    @ResponseBody
    @RequestMapping("addOrUpdate")
    public R add(ParkManager parkManager) {
    int i=    parkManagerService.addOrUpdate(parkManager);
        return i>0?R.OK():R.ERROR(500,"保存失败");
    }

    /**
     * 进入停车场管理
     *
     * @return
     */
    @RequestMapping("tolist")
    public String tolist() {

        return "/park/list";
    }


    /**
     * 查询停车场列表
     * 查询停车场列表
     *
     * @param parkManager
     * @param page
     * @param limit
     * @return
     */
    @ResponseBody
    @RequestMapping("list")
    public R list(ParkManager parkManager, Integer page, Integer limit) {

        PageHelper.startPage(page, limit);
        List<ParkManager> managerList = parkManagerService.list(parkManager);

        PageInfo<ParkManager> info = new PageInfo<>(managerList);
        return R.OK(info);


    }
}
